﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcControlsToolkit
{
    public class ProgressBar : Control
    {
        

        public int Value
        {
            get
            {
                if (Attributes.ContainsKey("value"))
                    return int.Parse(Attributes["value"]);
                else return 0;
            }
            set { Attributes["value"] = value.ToString().ToLower(); }
        }

        public string OnCreate
        {
            get { return Attributes["create"]; }
            set { Attributes["create"] = value; }
        }

        public string OnChange
        {
            get { return Attributes["change"]; }
            set { Attributes["change"] = value; }
        }

        public string OnComplete
        {
            get { return Attributes["complete"]; }
            set { Attributes["complete"] = value; }
        }


        public ProgressBar(string name): base(name)
        {
        }

        public override string GetJScript()
        {
            var result = new StringBuilder();

            foreach (string key in Attributes.Keys)
            {
                result.AppendFormat(", {0}: {1}", key, Attributes[key]);
            }

            if (result.Length > 0)
                result.Remove(0, 1);

            result.Append("});");

            result.Insert(0, "var " + Name+ " = $(\"#" + Name + "\").progressbar({");

            return result.ToString();
        }

        public override string GetHtml()
        {
            var result = new StringBuilder();

            result.AppendFormat("<div id='{0}'></div>", Name);

            return result.ToString();
        }
    }
}
